module.exports = (sequelize, DataTypes) => {
    const Renewal = sequelize.define(
        'Renewal',
        {
            id: {
                type: DataTypes.BIGINT.UNSIGNED,
                allowNull: false,
                autoIncrement: true,
                primaryKey: true
            },
            date: {
                type: DataTypes.DATEONLY,
                allowNull: false,
                validate: {
                    notNull: {
                        msg: '续租日期不能为空'
                    },
                    isDate: {
                        msg: '续租日期必须是一个日期格式'
                    }
                },
                comment: '续租日期'
            },
            month: {
                type: DataTypes.INTEGER.UNSIGNED,
                allowNull: false,
                validate: {
                    notNull: {
                        msg: '续租期限不能为空'
                    },
                    isInt: {
                        msg: '续租期限必须是一个整数'
                    }
                },
                comment: '续租期限'
            },
            counter_id: {
                type: DataTypes.BIGINT.UNSIGNED,
                allowNull: false,
                validate: {
                    notNull: {
                        msg: '专柜不能为空'
                    }
                },
                references: {
                    model: 'Counter',
                    key: 'id'
                },
                comment: '专柜外键'
            }
        },
        {
            tableName: 'renewal'
        }
    )
    Renewal.associate = function(models) {
        models.Renewal.belongsTo(models.Counter, { foreignKey: 'counter_id', targetKey: 'id' })
    }
    return Renewal
}
